package com.freewater.javabase.demo.designpattern.command2.withundo.client;

import com.freewater.javabase.demo.designpattern.command2.withundo.command.*;
import com.freewater.javabase.demo.designpattern.command2.withundo.invoker.RemoteControllerWithUndo;
import com.freewater.javabase.demo.designpattern.command2.withundo.receiver.CellingFan;
import com.freewater.javabase.demo.designpattern.command2.withundo.receiver.Garage;
import com.freewater.javabase.demo.designpattern.command2.withundo.receiver.Light;
import com.freewater.javabase.demo.designpattern.command2.withundo.receiver.Stereo;

/**
* 客户端
* Created by FreeWater on 2017/4/4.
*/
public class RemoteControllerTest {
	public static void main(String[] args) {
		Light kitchenLight = new Light("Kitchen");
		LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight);
		LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight);

		Light livingRoomLight = new Light("Living Room");
		LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
		LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

		CellingFan cellingFan = new CellingFan();
		CellingFanOnCommand cellingFanOnCommand = new CellingFanOnCommand(cellingFan);
		CellingFanOffCommand cellingFanOffCommand = new CellingFanOffCommand(cellingFan);

		Garage garage = new Garage();
		GarageDoorUpCommand garageDoorUpCommand = new GarageDoorUpCommand(garage);
		GarageDoorDownCommand garageDoorDownCommand = new GarageDoorDownCommand(garage);

		Stereo stereo = new Stereo();
		StereoOnWithCDCommand stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo);
		SteroOffCommand steroOffCommand = new SteroOffCommand(stereo);

		RemoteControllerWithUndo controller = new RemoteControllerWithUndo();
		controller.setCommand(0, kitchenLightOn, kitchenLightOff);
		controller.setCommand(1, livingRoomLightOn, livingRoomLightOff);
		controller.setCommand(2, cellingFanOnCommand, cellingFanOffCommand);
		controller.setCommand(3, garageDoorUpCommand, garageDoorDownCommand);
		controller.setCommand(4, stereoOnWithCDCommand, steroOffCommand);

		controller.onButtonWasPressed(0);
		controller.undoButtonWasPressed();
		controller.onButtonWasPressed(1);
		controller.undoButtonWasPressed();
		controller.onButtonWasPressed(2);
		controller.undoButtonWasPressed();
		controller.onButtonWasPressed(3);
		controller.undoButtonWasPressed();
		controller.onButtonWasPressed(4);
		controller.undoButtonWasPressed();

		controller.offButtonWasPressed(0);
		controller.undoButtonWasPressed();
		controller.offButtonWasPressed(1);
		controller.undoButtonWasPressed();
		controller.offButtonWasPressed(2);
		controller.undoButtonWasPressed();
		controller.offButtonWasPressed(3);
		controller.undoButtonWasPressed();
		controller.offButtonWasPressed(4);
		controller.undoButtonWasPressed();
	}
}
